namespace SimpleWebServices
{
    using System;
    using System.Globalization;
    using SimpleWebServices.Web.Mvc;

    public sealed class ResourceDecorationTest<T> : ITestExpectation
    {
        public string Path
        {
            get;
            set;
        }

        public bool Check()
        {
            ResourceAttribute attribute = Attribute.GetCustomAttribute(typeof(T), typeof(ResourceAttribute), false) as ResourceAttribute;
            if (null == attribute)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [Resource].", typeof(T).Name));
            }
            else if (this.Path != attribute.Path)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [Resource(Path = \"{1}\")].", typeof(T).Name, this.Path));
            }

            return true;
        }
    }
}